package com.molichuxing.services.infrastructure.service.impl;


import com.molichuxing.services.infrastructure.bean.VehiclePictureBean;
import com.molichuxing.services.infrastructure.convertor.Convert;
import com.molichuxing.services.infrastructure.dao.VehiclePictureMapper;
import com.molichuxing.services.infrastructure.dto.response.VehiclePictureDto;
import com.molichuxing.services.infrastructure.service.VehiclePictureService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 车型图片表 服务实现类
 * </p>
 *
 * @author 
 * @since 2019-08-12
 */
@Service("vehiclePictureService")
public class VehiclePictureServiceImpl  implements VehiclePictureService {

  @Autowired
  private VehiclePictureMapper vehiclePictureMapper;

  @Override
  public List<VehiclePictureDto> getVehiclePictureByVehicleId(Integer vehicleId) {
     //根据e车型id获取车型图片
      List<VehiclePictureBean> vehiclePictureBeanList = vehiclePictureMapper.selectVehiclePictureList(vehicleId);
      return  Convert.toVehiclePictureBeanDto(vehiclePictureBeanList);
  }

    @Override
    public Map<Integer, List<VehiclePictureDto>> getVehiclePictureByVehicleIds(List<Integer> vehicleIds) {
      if((null != vehicleIds)&&(vehicleIds.size() > 0)) {
          List<VehiclePictureBean> vehiclePictureBeanList = vehiclePictureMapper.selectVehiclePictureLists(vehicleIds);
          List<VehiclePictureDto> result = Convert.toVehiclePictureBeanDto(vehiclePictureBeanList);
          if((null != result)&&(result.size() != 0)) {
              return result.stream().collect(Collectors.groupingBy(VehiclePictureDto::getVehicleModelId));
          }
      }
      return null;
    }
}
